/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.setting.presenter;

import android.text.TextUtils;

import com.suozhang.framework.entity.bo.UserInfoBo;
import com.yiqi.liebang.entity.bo.EditPrivacyBo;
import com.yiqi.liebang.entity.bo.PrivacyBo;
import com.yiqi.liebang.entity.bo.UserCenterBo;
import com.yiqi.liebang.feature.mine.contract.UserContract;
import com.yiqi.liebang.feature.mine.dependencies.login.DaggerUserPresenterComponent;
import com.yiqi.liebang.feature.setting.contract.PrivacyContract;
import com.yiqi.liebang.feature.setting.dependencies.login.DaggerPrivacyPresenterComponent;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class PrivacyPresenter implements PrivacyContract.Presenter {

    private PrivacyContract.View mView;

    @Inject

    PrivacyContract.Model mModel;


    public PrivacyPresenter(PrivacyContract.View mView) {
        this.mView = mView;
        DaggerPrivacyPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getPrivacyData() {
        mModel.getPrivacyData().compose(mView.bindToLife()).subscribe(new Observer<PrivacyBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(PrivacyBo privacyBo) {
                mView.showPrivacySuccess(privacyBo);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void editPrivacy(String editType, String type, String blackUserUid) {

        EditPrivacyBo editPrivacyBo = null;
        if (TextUtils.isEmpty(blackUserUid)) {
            editPrivacyBo = new EditPrivacyBo(editType, type);
        } else {
            editPrivacyBo = new EditPrivacyBo();
            editPrivacyBo.setBlackUserUid(blackUserUid);
            editPrivacyBo.setEditType(editType);
        }


        mModel.editPrivacy(editPrivacyBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String privacyBo) {
                mView.showEditSuccess();
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.showError(e.getMessage());
                mView.dismissLoading();
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }
}
